#include "ProtectionPaladin.h"

#include "Paladin.h"
#include "PaladinSpells.h"
#include "TalentStatIncrease.h"

ProtectionPaladin::ProtectionPaladin(Paladin* paladin) :
    TalentTree("Protection", "Assets/paladin/paladin_protection.jpg"), paladin(paladin), spells(static_cast<PaladinSpells*>(paladin->get_spells())) {
    talent_names_to_locations = {
        {"Improved Devotion Aura", "1ML"},
        {"Redoubt", "1MR"},
        {"Precision", "2LL"},
        {"Guardian's Favor", "2ML"},
        {"Toughness", "2RR"},
        {"Blessing of Kings", "3LL"},
        {"Improved Righteous Fury", "3ML"},
        {"Shield Specialization", "3MR"},
        {"Anticipation", "3RR"},
        {"Improved Hammer of Justice", "4ML"},
        {"Improved Concentration Aura", "4MR"},
        {"Blessing of Sanctuary", "5ML"},
        {"Reckoning", "5MR"},
        {"One-Handed Weapon Specialization", "6MR"},
        {"Holy Shield", "7ML"},
    };

    QMap<QString, Talent*> tier1 {{"1ML", new Talent(paladin, this, "Improved Devotion Aura", "1ML", "Assets/spell/Spell_holy_devotionaura.png", 5,
                                                     "Increases the armor bonus of your Devotion Aura by %1%.",
                                                     QVector<QPair<unsigned, unsigned>> {{5, 5}})},
                                  {"1MR", new Talent(paladin, this, "Redoubt", "1MR", "Assets/ability/Ability_defend.png", 5,
                                                     "Increases your chance to block attacks with your shield by %1% after being the victim of a "
                                                     "critical strike. Lasts 10 sec or 5 blocks.",
                                                     QVector<QPair<unsigned, unsigned>> {{6, 6}})}};
    add_talents(tier1);

    QMap<QString, Talent*> tier2 {{"2ML", new Talent(paladin, this, "Guardian's Favor", "2ML", "Assets/spell/Spell_holy_sealofprotection.png", 2,
                                                     "Reduces the cooldown of your Blessing of Protection by %1 sec and increases the duration of "
                                                     "your Blessing of Freedom by %2 sec.",
                                                     QVector<QPair<unsigned, unsigned>> {{60, 60}, {3, 3}})},
                                  {"2RR", new Talent(paladin, this, "Toughness", "2RR", "Assets/spell/Spell_holy_devotion.png", 5,
                                                     "Increases the armor value from items by %1%", QVector<QPair<unsigned, unsigned>> {{2, 2}})}};
    add_precision(tier2);
    add_talents(tier2);

    QMap<QString, Talent*> tier3 {{"3LL", new Talent(paladin, this, "Blessing of Kings", "3LL", "Assets/spell/Spell_magic_magearmor.png", 1,
                                                     "Places a Blessing on the friendly target, increasing total stats by 10% for 5 min. Players may "
                                                     "only have one Blessing on them per Paladin at any one time.",
                                                     QVector<QPair<unsigned, unsigned>>())},
                                  {"3ML", new Talent(paladin, this, "Improved Righteous Fury", "3ML", "Assets/spell/Spell_holy_sealoffury.png", 3,
                                                     "Increases the amount of threat generated by your Righteous Fury spell by %1%.",
                                                     QVector<QPair<unsigned, unsigned>> {{16, 17}})},
                                  {"3MR", new Talent(paladin, this, "Shield Specialization", "3MR", "Assets/items/Inv_shield_06.png", 3,
                                                     "Increases the amount of damage absorbed by your shield by %1%.",
                                                     QVector<QPair<unsigned, unsigned>> {{10, 10}})},
                                  {"3RR", new Talent(paladin, this, "Anticipation", "3RR", "Assets/spell/Spell_nature_mirrorimage.png", 5,
                                                     "Increases your Defense skill by %1.", QVector<QPair<unsigned, unsigned>> {{2, 2}})}};
    add_talents(tier3);

    QMap<QString, Talent*> tier4 {{"4ML", new Talent(paladin, this, "Improved Hammer of Justice", "4ML", "Assets/spell/Spell_holy_sealofmight.png", 3,
                                                     "Decreases the cooldown of your Hammer of Justice spell by %1 sec.",
                                                     QVector<QPair<unsigned, unsigned>> {{5, 5}})},
                                  {"4MR", new Talent(paladin, this, "Improved Concentration Aura", "4MR", "Assets/spell/Spell_holy_mindsooth.png", 3,
                                                     "Increases the effect of your Concentration Aura by an additional %1% and gives all group "
                                                     "members affected by the aura an additional %2% chance to resist Silence and Interrupt effects.",
                                                     QVector<QPair<unsigned, unsigned>> {{5, 5}, {5, 5}})}};
    add_talents(tier4);

    QMap<QString, Talent*> tier5 {{"5ML", new Talent(paladin, this, "Blessing of Sanctuary", "5ML", "Assets/spell/Spell_nature_lightningshield.png", 1,
                                                     "Places a Blessing on the friendly target, reducing damage dealt from all sources by up to 10 "
                                                     "for 5 min. In addition, when the target blocks a melee attack the attacker will take 14 Holy "
                                                     "damage. Players may only have one Blessing on them per Paladin at any one time.",
                                                     QVector<QPair<unsigned, unsigned>>())},
                                  {"5MR", new Talent(paladin, this, "Reckoning", "5MR", "Assets/spell/Spell_holy_blessingofstrength.png", 5,
                                                     "Gives you a %1% chance to gain an extra attack after being the victim of a critical strike.",
                                                     QVector<QPair<unsigned, unsigned>> {{20, 20}})}};
    add_talents(tier5);

    QMap<QString, Talent*> tier6 {};
    add_one_handed_weapon_specialization(tier6);
    add_talents(tier6);

    QMap<QString, Talent*> tier7 {
        {"7ML", new Talent(paladin, this, "Holy Shield", "7ML", "Assets/spell/Spell_holy_blessingofprotection.png", 1,
                           "Increases chance to block by 30% for 10 sec, and deals 65 Holy damage for each attack blocked while active. Damage "
                           "caused by Holy Shield causes 20% additional threat. Each block expends a charge. 4 charges.",
                           QVector<QPair<unsigned, unsigned>>())}};
    add_talents(tier7);

    talents["1MR"]->talent->set_bottom_child(talents["3MR"]->talent);
    talents["3MR"]->talent->set_parent(talents["1MR"]->talent);

    talents["5ML"]->talent->set_bottom_child(talents["7ML"]->talent);
    talents["7ML"]->talent->set_parent(talents["5ML"]->talent);
}

void ProtectionPaladin::add_precision(QMap<QString, Talent*>& talent_tier) {
    auto talent = new TalentStatIncrease(paladin, this, "Precision", "2LL", "Assets/ability/Ability_rogue_ambush.png", 3,
                                         "Increases your chance to hit with melee weapons by %1%.", QVector<QPair<unsigned, unsigned>> {{1, 1}},
                                         QVector<QPair<TalentStat, unsigned>> {{TalentStat::MeleeHit, 100}, {TalentStat::RangedHit, 100}});

    add_talent_to_tier(talent_tier, talent);
}

void ProtectionPaladin::add_one_handed_weapon_specialization(QMap<QString, Talent*>& talent_tier) {
    auto talent = new TalentStatIncrease(paladin, this, "One-Handed Weapon Specialization", "6MR", "Assets/items/Inv_sword_20.png", 5,
                                         "Increases the damage you deal with One-Handed Melee weapons by %1%.",
                                         QVector<QPair<unsigned, unsigned>> {{2, 2}},
                                         QVector<QPair<TalentStat, unsigned>> {{TalentStat::OneHandMeleeDmg, 2}});

    add_talent_to_tier(talent_tier, talent);
}
